package org.parademo.web.model;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindingResult;

import java.util.Date;

public class ProposalFormView {
    private Long id;
    private String title;
    private String description;
    private Long topicId;
    private String topic;
    private Date votingEndDate;
    private boolean submitted;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getTopicId() {
        return topicId;
    }

    public void setTopicId(Long topicId) {
        this.topicId = topicId;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public Date getVotingEndDate() {
        return votingEndDate;
    }

    public void setVotingEndDate(Date votingEndDate) {
        this.votingEndDate = votingEndDate;
    }

    public boolean isSubmitted() {
        return submitted;
    }

    public void setSubmitted(boolean submitted) {
        this.submitted = submitted;
    }

    public void validateUsing(BindingResult bindingResult) {
        if (StringUtils.isEmpty(title)) {
            bindingResult.rejectValue("title", "proposal.create.validation.title.required");
        }
        if (StringUtils.isEmpty(description)) {
            bindingResult.rejectValue("description", "proposal.create.validation.description.required");
        }
        if (topicId == null || topicId == 0) {
            bindingResult.rejectValue("topicId", "proposal.create.validation.topicId.required");
        }
        if (votingEndDate == null) {
            bindingResult.rejectValue("votingEndDate", "proposal.create.validation.votingEndDate.required");
        }
    }
}
